package com.caidan.search.controller;

import cn.hutool.core.util.StrUtil;
import com.caidan.common.result.Result;
import com.caidan.common.result.ResultCodeEnum;
import com.caidan.common.util.PhoneNumberValidator;
import com.caidan.search.service.MsgService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @项目名 CaiDanSearchSystem
 * @描述 短信接口
 * @作者 小菜蛋
 * @时间 2024/12/2 16:51
 */
@RequestMapping("/msg")
@RestController
@Slf4j
public class MsgController {

    @Resource
    private MsgService msgService;
    @GetMapping
    public Result<String> getCode(String phoneNumber){
        if(StrUtil.isBlank(phoneNumber)){
            return Result.fail(ResultCodeEnum.ARGUMENT_VALID_ERROR.getMessage());
        }
        if(!PhoneNumberValidator.isValidPhoneNumber(phoneNumber)){
            return Result.fail(ResultCodeEnum.PHONE_ERROR.getMessage());
        }
        return msgService.getCode(phoneNumber);
    }
}
